<?php

/**
 * Vehicle form.
 *
 * @package    MVM Vehicle Showroom (r)
 * @subpackage form
 * @author     Bo Wang < beau32 [at] gmail.com >
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class VehicleForm extends BaseVehicleForm {
  public function configure() {
    unset($this['created_at'], $this['updated_at']);

    $this->widgetSchema['is_featured']= new sfWidgetFormInputCheckbox(array(),array('value'=>1));
    $this->widgetSchema['is_special']= new sfWidgetFormInputCheckbox(array(),array('value'=>1));
    $this->widgetSchema['transmission']= new sfWidgetFormSelect(array('choices' =>VehicleTable::$conts['vehicle_transmission']));
    $this->widgetSchema['fuel']= new sfWidgetFormSelect(array('choices' =>VehicleTable::$conts['vehicle_fuel']));

	$val = range(0,5);
	unset($val[0]);
    $this->widgetSchema['doors']= new sfWidgetFormSelect(array('choices' =>$val));
    $this->widgetSchema['description'] = new sfWidgetFormTextareaTinyMCE(array(
                    'width'  => 350,
                    'height' => 450,
                    'config' => 'theme_advanced_disable: "anchor,image,cleanup,help"',

    ));

    if(!$this->isNew()) {
      $models = $this->getObject()->getMake()->getModels();
    }else {
      $models = ModelTable::getInstance()->findByMakeId(1);
    }
    $md = array();
    foreach($models as $m) {
      $md[$m->getId()]=$m->getName();
    }
    $this->widgetSchema['model_id']= new sfWidgetFormChoice(array('choices'=>$md));

    $month = array();
    for($i=0;$i<13;$i++) {
      $month[strtotime('+'.$i.' month')] = date('F Y',strtotime('+'.$i.' month'));
    }

    array_unshift($month,'No WOF');
    $this->widgetSchema['wof_expires']= new sfWidgetFormSelect(array('choices' =>$month));

    array_shift($month);
    array_unshift($month,'No Registration');
    $this->widgetSchema['registration_expires']= new sfWidgetFormSelect(array('choices' =>$month));

    for($i=1; $i<=sfConfig::get('app_number_image_allowed'); $i++) {
      $this->widgetSchema['picture_'.$i] = new sfWidgetFormInputHidden();
      if(!$this->isNew() && $this->getObject()->getPicture($i)) {
        $this->widgetSchema['picture_'.$i]->setDefault($this->getObject()->getPicture($i)->getFilename());
      }
      $this->validatorSchema['picture_'.$i] = new sfValidatorString(array('required'=> 0),array('required' => 'Required'));
    }


  }

}
